package com.zrwl.poscloud.xo.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.entity.CompanyPayConfig;
import com.zrwl.poscloud.base.superI.SuperMapper;
import com.zrwl.poscloud.xo.vo.CompanyPayConfigVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 在线支付商户信息 Mapper类
 *
 * @author 刘思童 AutoGenerate
 * @date 2021-06-11
 */
public interface CompanyPayConfigMapper extends SuperMapper<CompanyPayConfig> {

    @Select("<script>" +
            " SELECT a.*,b.name feeName,(c.sys_min+c.way_min) feeMin,(c.sys_max+c.way_max) feeMax,(c.sys_rate+c.way_rate) feeRate,  " +
            "  if(a.owner_type = 1, (select name from t_merchant where status != 0 and uid = owner_uid), " +
            "          if(a.owner_type = 2, (select short_name from t_company where status != 0 and uid = owner_uid),null))owner_name " +
            " FROM t_company_pay_config a LEFT JOIN t_account_fee b ON a.fee_uid=b.uid LEFT JOIN t_account_fee_config c ON a.fee_uid=c.account_fee_uid " +
            " WHERE a.status!=0 AND b.status=1 AND c.status=1  " +
            " <if test='param.keyword!=null and param.keyword!=&quot;&quot;'>" +
            " AND (a.merchant_name LIKE CONCAT('%',#{param.keyword},'%') " +
            " OR a.merchant_code LIKE CONCAT('%',#{param.keyword},'%')) " +
            " </if>" +
            " <if test='param.ownerUid!=null and param.ownerUid!=&quot;&quot;'>" +
            " AND a.owner_uid = #{param.ownerUid}" +
            " </if>" +
            " <if test='param.wayType!=0'>" +
            " AND a.way_type = #{param.wayType}" +
            " </if>" +
            " <if test='param.platType!=0'>" +
            " AND a.plat_type = #{param.platType}" +
            " </if>" +
            "  <if test='param.chargeTypeList != null and param.chargeTypeList.length > 0'>" +
            "            and  " +
            "            <foreach item='item' index='index' collection='param.chargeTypeList' " +
            "                     open='(' separator='or' close=')'> " +
            "                charge_type like concat('%',#{item},'%') " +
            "            </foreach> " +
            "        </if>" +
            " ORDER BY a.update_time DESC " +
            "</script>"
    )
    public IPage<CompanyPayConfigVO> getCompanyPayConfigList(Page page, @Param("param") CompanyPayConfigVO companyPayConfigVO);

    @Select("<script>" +
            " SELECT a.*,c.sys_min sysMin,c.way_min wayMin,c.sys_max sysMax,c.way_max wayMax,c.sys_rate sysRate,c.way_rate wayRate " +
            " FROM t_company_pay_config a LEFT JOIN t_account_fee b ON a.fee_uid=b.uid LEFT JOIN t_account_fee_config c ON a.fee_uid=c.account_fee_uid " +
            " WHERE a.status!=0 AND b.status=1 AND c.status=1 AND a.owner_uid = #{param.ownerUid} " +
            " ORDER BY a.update_time DESC " +
            "</script>"
    )
    public List<CompanyPayConfigVO> getCompanyPayConfigListForMobile(@Param("param") CompanyPayConfigVO companyPayConfigVO);
}
